package Base.ExtendTest;

/*
 * @author 枫城
 * @createTime 2022/9/3 23:05
 * @desc 通过继承Account，模拟行用卡
 */
public class CheckAccount extends Account{

    private double overdraft; // 可透支额度

    public CheckAccount(int id, double balance, double annualInterestRate, double overdraft) {
        super(id, balance, annualInterestRate);
        this.overdraft = overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double amount) {
        if (getBalance() >= amount){ // 余额足够
            // 通过super关键字调用父类中的方法
            super.withdraw(amount);
        }else if (overdraft >= (amount - getBalance())){ // 透支额度
            overdraft -= (amount - getBalance());
            setBalance(0);
        }else {
            System.out.println("额度不够，可卖肾来凑");
        }
    }
}
